package ${package.Es};

import javax.annotation.Resource;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import ${package.Stereotype}.elasticsearch.ElasticsearchHandler;
import ${package.Stereotype}.elasticsearch.ElasticsearchRecord;
import ${package.Stereotype}.elasticsearch.ElasticsearchVo;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import ${package.Service}.${table.serviceName};
import ${package.Vo}.${table.voName};
import java.util.List;

/**
 * <p>
 * ${table.comment!} => Elasticsearch聚合查询(key: ${entity})
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Slf4j
@Component
public class ${entity}ElasticsearchHandler implements ElasticsearchHandler {

    @Resource
    private ${table.serviceName} ${table.layuiServiceName};

    private String type = "${entity}";

    @Override
    public String getType() {
        return this.type;
    }

    @Override
    public boolean canDeal(ElasticsearchVo vo) {
        return !StringUtils.hasLength(vo.getType()) || this.type.equals(vo.getType());
    }

<#assign elasticsearchRecord = 'ElasticsearchRecord' />
    @Override
    public List<${elasticsearchRecord}> deal(ElasticsearchVo elasticsearchVo) {
        ${table.voName} vo = new ${table.voName}();
        vo.setPage(0);
        vo.setLimit(10);
        vo.setName(elasticsearchVo.getName());
        PageInfo page = ${table.layuiServiceName}.page${table.entityName}Es(vo);
        return null == page ? null : page.getList();
    }

}
